00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015 #ifndef EXPORTLINE33_HPP_
00016 #define EXPORTLINE33_HPP_
00017
00018 #include <iostream>
00019 #include <string>
00020 #include <vector>
00021 #include <map>
00022
00023 #include "gridpack/parallel/communicator.hpp"
00024 #include "gridpack/component/data_collection.hpp"
00025 #include "gridpack/parser/dictionary.hpp"
00026 #include "gridpack/network/base_network.hpp"
00027 #include "gridpack/export/base_export.hpp"
00028
00029 namespace gridpack {
00030 namespace expnet {
00031
00032 template <class _network>
00033 class ExportLine33
00034 {
00035 public:
00036
00037
00038
00039
00040 explicit ExportLine33(boost::shared_ptr<_network> network) :
00041 p_network(network), p_comm(network->communicator())
00042 {
00043 }
00044
00045
00046
00047
00048 virtual ~ExportLine33(){}
00049
00050
00051
00052
00053
00054
00055
00056
00057 void writeLineBlock(std::ofstream &fout)
00058 {
00059 BaseExport<_network> exprt(p_comm);
00060 int me = p_comm.rank();
00061
00062 int nbranch = p_network->numBranches();
00063 gridpack::component::DataCollection *data;
00064 int i, j;
00065 char buf[MAX_STRING_SIZE];
00066 std::vector<text_line> text_data;
00067 for (i=0; i<nbranch; i++) {
00068 if (p_network->getActiveBranch(i)) {
00069 data = p_network->getBranchData(i).get();
00070 double rval;
00071 int ival;
00072 int idx1, idx2;
00073 std::string sval;
00074 DoubleComplex zval;
00075 char *ptr;
00076 int nline = 0;
00077 double tap_ratio;
00078 data->getValue(BRANCH_NUM_ELEMENTS,&nline);
00079 for (j=0; j<nline; j++) {
00080 ptr = buf;
00081 data->getValue(BRANCH_TAP,&tap_ratio,j);
00082 bool is_xform = data->getValue(TRANSFORMER_WINDV1,&rval,j);
00083 is_xform = is_xform && data->getValue(TRANSFORMER_WINDV2,&rval,j);
00084 if (!is_xform && (tap_ratio == 0.0 || tap_ratio == 1.0)) {
00085 data->getValue(BRANCH_FROMBUS,&idx1);
00086 data->getValue(BRANCH_TOBUS,&idx2);
00087 ival = 1;
00088 data->getValue(BRANCH_SWITCHED,&ival,j);
00089 if (ival == 1) {
00090 sprintf(ptr,"%d, %d",idx1,idx2);
00091 } else {
00092 sprintf(ptr,"%d, %d",idx2,idx1);
00093 }
00094 ptr += strlen(ptr);
00095 sval = " 1",
00096 data->getValue(BRANCH_CKT,&sval,j);
00097 sprintf(ptr," \'%s\',",sval.c_str());
00098 ptr += strlen(ptr);
00099
00100 data->getValue(BRANCH_R,&rval,j);
00101 sprintf(ptr," %f,",rval);
00102 ptr += strlen(ptr);
00103
00104 data->getValue(BRANCH_X,&rval,j);
00105 sprintf(ptr," %f,",rval);
00106 ptr += strlen(ptr);
00107 rval = 0.0;
00108 data->getValue(BRANCH_B,&rval,j);
00109 sprintf(ptr," %f,",rval);
00110 ptr += strlen(ptr);
00111
00112 data->getValue(BRANCH_RATING_A,&rval,j);
00113 sprintf(ptr," %f,",rval);
00114 ptr += strlen(ptr);
00115 rval = 0.0;
00116 data->getValue(BRANCH_RATING_B,&rval,j);
00117 sprintf(ptr," %f,",rval);
00118 ptr += strlen(ptr);
00119 rval = 0.0;
00120 data->getValue(BRANCH_RATING_C,&rval,j);
00121 sprintf(ptr," %f,",rval);
00122 ptr += strlen(ptr);
00123 rval = 0.0;
00124 data->getValue(BRANCH_SHUNT_ADMTTNC_G1,&rval,j);
00125 sprintf(ptr," %f,",rval);
00126 ptr += strlen(ptr);
00127 rval = 0.0;
00128 data->getValue(BRANCH_SHUNT_ADMTTNC_B1,&rval,j);
00129 sprintf(ptr," %f,",rval);
00130 ptr += strlen(ptr);
00131 rval = 0.0;
00132 data->getValue(BRANCH_SHUNT_ADMTTNC_G2,&rval,j);
00133 sprintf(ptr," %f,",rval);
00134 ptr += strlen(ptr);
00135 rval = 0.0;
00136 data->getValue(BRANCH_SHUNT_ADMTTNC_B2,&rval,j);
00137 sprintf(ptr," %f,",rval);
00138 ptr += strlen(ptr);
00139 ival = 1;
00140 data->getValue(BRANCH_STATUS,&ival,j);
00141 sprintf(ptr,"%d,",ival);
00142 ptr += strlen(ptr);
00143 ival = 1;
00144 data->getValue(BRANCH_METER,&ival,j);
00145 sprintf(ptr,"%d,",ival);
00146 ptr += strlen(ptr);
00147 rval = 0.0;
00148 data->getValue(BRANCH_LENGTH,&rval,j);
00149 sprintf(ptr," %f",rval);
00150 ptr += strlen(ptr);
00151 if (data->getValue(BRANCH_O1,&ival,j) &&
00152 data->getValue(BRANCH_F1,&rval,j)) {
00153 sprintf(ptr,", %d, %f",ival,rval);
00154 ptr += strlen(ptr);
00155 }
00156 if (data->getValue(BRANCH_O2,&ival,j) &&
00157 data->getValue(BRANCH_F2,&rval,j)) {
00158 sprintf(ptr,", %d, %f",ival,rval);
00159 ptr += strlen(ptr);
00160 }
00161 if (data->getValue(BRANCH_O3,&ival,j) &&
00162 data->getValue(BRANCH_F3,&rval,j)) {
00163 sprintf(ptr,", %d, %f",ival,rval);
00164 ptr += strlen(ptr);
00165 }
00166 if (data->getValue(BRANCH_O4,&ival,j) &&
00167 data->getValue(BRANCH_F4,&rval,j)) {
00168 sprintf(ptr,", %d, %f",ival,rval);
00169 ptr += strlen(ptr);
00170 }
00171 sprintf(ptr,"\n");
00172 text_line text;
00173 strcpy(text.text,buf);
00174 text.global_idx = p_network->getGlobalBranchIndex(i);
00175 text.device_idx = j;
00176 text_data.push_back(text);
00177 }
00178 }
00179 }
00180 }
00181 if (me == 0) {
00182 fout << "0 / END GENERATOR DATA, BEGIN LINE DATA" << std::endl;
00183 }
00184 exprt.writeDataBlock(fout, text_data);
00185 }
00186
00187 private:
00188 boost::shared_ptr<_network> p_network;
00189
00190 gridpack::parallel::Communicator p_comm;
00191 };
00192
00193 }
00194 }
00195
00196 #endif